package com.antbee.cost.assistant.daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.antbee.cost.assistant.dao.AssistConDAO;
import com.antbee.cost.assistant.dao.AssistDAO;
import com.antbee.cost.hibernate.model.CostAssistant;
import com.antbee.cost.hibernate.model.CostAssistantCon;
import com.antbee.cost.hibernate.model.CostEngineer;



public class AssistConDAOImpl extends HibernateDaoSupport implements AssistConDAO {

	public CostAssistantCon GetAssist(String Assid) {
		// TODO Auto-generated method stub
		List Lsql = this.getHibernateTemplate().find("from CostAssistantCon as a where a.assid="+Assid);
		if (Lsql.size()>= 1){	
			if (Lsql.get(0)!= null){
				return (CostAssistantCon) Lsql.get(0);
			}
			
		}
		return null ;
	}

	public List GetEngineerAssist(String CerNo) {
		// TODO Auto-generated method stub
		if (CerNo.equals("")){
			return null;
		}
		List Lsql = this.getHibernateTemplate().find("from CostAssistantCon as a where a.costEngineer.costId="+CerNo);		
		return Lsql;
	}

	public void ModifyAssist(CostAssistantCon assist,String CerNo) {
		// TODO Auto-generated method stub
		List Lsql = this.getHibernateTemplate().find("from CostEngineer as a where a.costId="+CerNo);
		CostEngineer li = (CostEngineer) Lsql.get(0);
		assist.setCostEngineer(li);
		this.getHibernateTemplate().saveOrUpdate(assist);
	}

	public void DelAssist(String Assid) {
		CostAssistantCon assit = this.GetAssist(Assid);
		this.getHibernateTemplate().delete(assit);		
	}
	public List getAssisAll() {
		List Lsql = this.getHibernateTemplate().find("from CostAssistantCon");
		return Lsql;
	}

}
